package org.example.controller;

import org.example.common.JsonCode;
import org.example.entity.Student;
import org.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService s;

    @GetMapping
    public List<Student> getAll() {
        List<Student> all = s.getAll();
        return all;
    }
    @GetMapping("/{id}")
    public Student getById(@PathVariable Integer id) {
        Student byId = s.getById(id);
        return byId;
    }
    @PostMapping
    public JsonCode insert(Student student) {
        s.insert(student);
        return JsonCode.getJson();
    }
    @PutMapping
    public JsonCode update(Student student) {
        s.update(student);
        return JsonCode.getJson();
    }
    @DeleteMapping("/{id}")
    public JsonCode delete(@PathVariable Integer id) {
        s.delete(id);
        return JsonCode.getJson();
    }

}
